// app.js
App({
  onLaunch() {
    console.log(wx.getStorageSync('token'))
    if(wx.getStorageSync('token')){
      console.log('-------------------------------------------')
      wx.request({
        url:'http://localhost:3000/user/customer',
        header:{'Authorization':wx.getStorageSync('token')},
        success:res=>{
          // let userInfo=res.data[0]
          // console.log(res)
          // console.log(userInfo)
          // wx.setStorageSync('user',{
          //   userId:userInfo.userId,
          //   userName: userInfo.userName,
          //   headPhoto: userInfo.headPhoto
          // })
          
          wx.switchTab({
            url: '/pages/home/home',
          })
        }
      })
    }
    else{
      //登录
      wx.login({
        success: res => {
          // 发送 res.code 到后台换取 openId, sessionKey, unionId
          console.log('hhhhhhhhhhhhhhhhhhhhhhhhhhhhh')
          console.log('res.code:'+res.code)
          wx.request({
            url:`http://localhost:3000/user/login/${res.code}`,
            dataType:'text',
            success:res=>{
              console.log(res.data)
              wx.setStorageSync('token', res.data)
              // wx.getStorageSync('userId',res.data)
              wx.navigateTo({
                url:'/pages/authorize/authorize'
              })
            }
          })
        }
      })
    }
  },
  globalData: {
    userInfo: null,
    url:'http://localhost:3000',
    user:wx.getStorageSync('user'),
    // mylist:[],
    collectdrugId:[],//收藏的药品的id
    inputValue_dy:''//保存自己上传的动态的输入框中的内容
  }
})
